/**
 * Created by LuckyYe on 2016/8/17.
 */
angular.module('service.pushques', [
        "ngResource",
        "ngStorage"
    ])
    .service('PushQuesService', ['$resource', '$http', '$q', function ($resource, $http, $q) {
        var tocpicUrl = mall_expert + "topic/";

        this.addTopicQue = function (topic, success_func, error_func) {
            var topicUrl = $resource(tocpicUrl);
            return topicUrl.save(topic, success_func, error_func);
        }

        //图片上传
        this.uploadFile = function (imgsrc, img, imgName) {
            var postData = {
                filename: imgsrc,
                file: img
            };
            var fd = new FormData();
            angular.forEach(postData, function (val, key) {
                fd.append(key, val, imgName);
            });
            var deferred = $q.defer();
            $http({
                method: 'POST',
                url: mall_uc + 'fileupload/picupload',
                data: fd,
                headers: {'Content-Type': undefined},
                transformRequest: angular.identity
            }).success(function (data, status, headers, config) {
                deferred.resolve(data);
            }).error(function (data, status, headers, config) {
                deferred.reject(data);
            });
            return deferred.promise;
        }

    }])